


import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';

abstract class SvgLoadable {

  /// Instantiates a widget that renders an SVG picture from an [AssetBundle].
  ///
  /// The key will be derived from the `assetName`, `package`, and `bundle`
  /// arguments. The `package` argument must be non-null when displaying an SVG
  /// from a package and null otherwise. See the `Assets in packages` section for
  /// details.
  ///
  /// Either the [width] and [height] arguments should be specified, or the
  /// widget should be placed in a context that sets tight layout constraints.
  /// Otherwise, the image dimensions will change as the image is loaded, which
  /// will result in ugly layout changes.
  ///
  SvgPicture asset(
      String name, {
        Key? key,
        AssetBundle? bundle,
        String? package,
        bool matchTextDirection = false,
        double? width,
        double? height,
        BoxFit fit = BoxFit.contain,
        Alignment alignment = Alignment.center,
        Color? color,
        BlendMode colorBlendMode = BlendMode.srcIn,
      }) {
    return SvgPicture.asset(
      name,
      key: key,
      bundle: bundle,
      matchTextDirection: matchTextDirection,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      color: color,
      colorBlendMode: colorBlendMode,
    );
  }

  SvgPicture network(
      String url, {
        Key? key,
        String? package,
        bool matchTextDirection = false,
        double? width,
        double? height,
        BoxFit fit = BoxFit.contain,
        Alignment alignment = Alignment.center,
        Color? color,
        BlendMode colorBlendMode = BlendMode.srcIn,
        Widget? placeholderWidget,
      }) {
    return SvgPicture.network(
      url,
      key: key,
      matchTextDirection: matchTextDirection,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      color: color,
      colorBlendMode: colorBlendMode,
      placeholderBuilder: (context) {
        return placeholderWidget ??
            Container(
              color: Colors.transparent,
            );
      },
    );
  }

  SvgPicture file(
      File file, {
        Key? key,
        String? package,
        bool matchTextDirection = false,
        double? width,
        double? height,
        BoxFit fit = BoxFit.contain,
        Alignment alignment = Alignment.center,
        Color? color,
        BlendMode colorBlendMode = BlendMode.srcIn,
        Widget? placeholderWidget,
      }) {
    return SvgPicture.file(
      file,
      key: key,
      matchTextDirection: matchTextDirection,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      color: color,
      colorBlendMode: colorBlendMode,
      placeholderBuilder: (context) {
        return placeholderWidget ??
            Container(
              color: Colors.transparent,
            );
      },
    );
  }

  SvgPicture memory(
      Uint8List bytes, {
        Key? key,
        String? package,
        bool matchTextDirection = false,
        double? width,
        double? height,
        BoxFit fit = BoxFit.contain,
        Alignment alignment = Alignment.center,
        Color? color,
        BlendMode colorBlendMode = BlendMode.srcIn,
        Widget? placeholderWidget,
      }) {
    return SvgPicture.memory(
      bytes,
      key: key,
      matchTextDirection: matchTextDirection,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      color: color,
      colorBlendMode: colorBlendMode,
      placeholderBuilder: (context) {
        return placeholderWidget ??
            Container(
              color: Colors.transparent,
            );
      },
    );
  }

  SvgPicture string(
      String bytes, {
        Key? key,
        String? package,
        bool matchTextDirection = false,
        double? width,
        double? height,
        BoxFit fit = BoxFit.contain,
        Alignment alignment = Alignment.center,
        Color? color,
        BlendMode colorBlendMode = BlendMode.srcIn,
        Widget? placeholderWidget,
      }) {
    return SvgPicture.string(
      bytes,
      key: key,
      matchTextDirection: matchTextDirection,
      width: width,
      height: height,
      fit: fit,
      alignment: alignment,
      color: color,
      colorBlendMode: colorBlendMode,
      placeholderBuilder: (context) {
        return placeholderWidget ??
            Container(
              color: Colors.transparent,
            );
      },
    );
  }
}